package com.hulk.dryad.common.constant.enums;

import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.EnumSet;

/**
 * @author lqx
 * @date  2020/10/13.
 * 客户登录状态
 */
public enum CustomerLoginStatus {

    NORMAL("NORMAL", "CustomerLoginStatus_NORMAL"),
    FREEZE("FREEZE", "CustomerLoginStatus_FREEZE"),
    LOCK("LOCK", "CustomerLoginStatus_LOCK"),
    FORBIDDEN("FORBIDDEN", "CustomerLoginStatus_BANLOGON"),
    INACTIVE("INACTIVE", "CustomerLoginStatus_INACTIVE"),
	REGISTER_FAIL("REGISTER_FAIL", "CustomerLoginStatus_REGISTER_FAIL"),
    DISBIND("DISBIND", "CustomerLoginStatus_DISBIND"),;

    /**
     * 类型
     */
    @Getter
    private String type;
    /**
     * 描述
     */
    private String description;

    CustomerLoginStatus(String type, String description) {
        this.type = type;
        this.description = description;
    }

    public String getDesc() {
        return messageSource.getMessage(description, null, description, LocaleContextHolder.getLocale());
    }


    private MessageSource messageSource;

    public CustomerLoginStatus setMessageSource(MessageSource messageSource) {
        this.messageSource = messageSource;
        return this;
    }


    @Component
    public static class ReportTypeServiceInjector {

        @Autowired
        private MessageSource messageSource;

        @PostConstruct
        public void postConstruct() {
            for (CustomerLoginStatus ec : EnumSet.allOf(CustomerLoginStatus.class)) {
                ec.setMessageSource(messageSource);
            }
        }
    }
}
